<template>
  <div class="content-box">
    <nav-title title="资格证书" />
    <div class="line">
      <span class="important"></span>
      <div class="label">名称</div>
      <div class="value">
        <input type="text" placeholder="请在此输入" v-model="qualty.cName" readonly="readonly">
      </div>
    </div>
    <div class="line">
      <span class="important"></span>
      <div class="label">等级</div>
      <div class="value">
        <input type="text" placeholder="请在此输入" v-model="qualty.cLevel" readonly="readonly">
      </div>
    </div>
    <div class="line">
      <span class="important"></span>
      <div class="label">签发单位</div>
      <div class="value">
        <input type="text" placeholder="请在此输入" v-model="qualty.cCompany" readonly="readonly">
      </div>
    </div>
    <div class="line">
      <span class="important"></span>
      <div class="label">签发日期</div>
      <div class="value">
        <group>
          <datetime value-text-align="left" readonly placeholder="请选择" v-model="qualty.cDate"></datetime>
        </group>
      </div>
    </div>
    <div class="line">
      <span class="important"></span>
      <div class="label">有效期</div>
      <div class="value">
        <group>
          <datetime value-text-align="left" readonly placeholder="请选择" v-model="qualty.cDate1"></datetime>
        </group>
      </div>
    </div>
    <div class="submit-btn" @click="save" v-if="showOr">
      保存
    </div>
    <div class="remove-btn" @click="remove" v-if="showOr">
      删除
    </div>
  </div>

</template>

<script>
import { Datetime, Group, PopupRadio } from 'vux'
import { editpqual, delQualification, getDicItem, getTrsNum } from '../../../api/api'
import { json2Form } from '../../../util/http'

export default {

  name: 'input-information',
  components: {
    Datetime, Group, PopupRadio
  },
  mounted(){
    //获取字典
    //this.getDic()
    if(this.$route.params.cnta){
      this.qualty.cTransactionNbr = this.$route.params.cnta
    }
  },
  created() {
    this.getQal()
  },
  data() {
    return {
     qualty:{
      emplid: '10070226',
      cModStauts:'',
      cTransactionNbr:''
    },

    saves:[],
    showOr: true

    }
  },
  methods: {
    // getDic(){
    //   //存档状态字典
    //   getDicItem({fileName: 'C_SAVE_STATUS'}).then(res=>{
    //     if(res && res.retCode === '000000'){
    //       for(let i=0; i<res.retData.length; i++){
    //         this.saves.push({value: res.retData[i].xlatshortname,key: res.retData[i].fieldvalue});
    //       }
    //     }
    //   }).catch(res=>{

    //   });
    // },
    save() {
      if(this.qualty.cModStauts == 'U'){
        this.qualty.cModStauts = 'U'
      }else{
        this.qualty.cModStauts = 'C'
      }
      // if(this.name === ''){
      //   this.$vux.alert.show({
      //     title: '警告',
      //     content: '请输入名称'
      //   });
      //   return;
      // }

      // if(this.qfDate === ''){
      //   this.$vux.alert.show({
      //     title: '警告',
      //     content: '请选择签发日期'
      //   });
      //   return;
      // }
      console.log(this.qualty)
      editpqual(json2Form(this.qualty)).then(res => {
        const that = this;
        //成功：000000
        if(res && res.retCode === '000000' ){
          //保存成功
          this.$vux.alert.show({
            title: '奥克斯',
            content: '保存成功',
            onHide () {
              that.$router.push({
                name: 'userBase',
                params:{
                  cnta: that.qualty.cTransactionNbr
                }
              });
            }
          })

        }else{
          // 显示
          this.$vux.alert.show({
            title: '提示',
            content: res.retMsg
          })
        }
      }).catch (res=>{
        this.$vux.alert.show({
          title: '警告',
          content: '网络异常，请稍后重试'
        })
      })
    },

    remove() {

      const _this = this;
      _this.qualty.cModStauts = 'D'
      _this.$vux.confirm.show({
          // 组件除show外的属性
          title: '提示',
          content: '确定删除？',
          onCancel () {
          },
          onConfirm () {
            console.log(_this.qualty.cModStauts)
            editpqual(json2Form(_this.qualty)).then(res=>{
              //成功：000000
              if(res && res.retCode === '000000' ){
                //删除成功
                // _this.$vux.alert.show({
                //   title: '奥克斯',
                //   content: '删除成功',
                //   onHide () {
                    _this.$router.push({
                      name: 'userBase',
                      params:{
                        cnta: _this.qualty.cTransactionNbr
                      }
                    });
                //   }
                // })
              }else{
                // 显示
                _this.$vux.alert.show({
                  title: '提示',
                  content: res.retMsg
                })
              }

            })
            .catch(res=>{
              _this.$vux.alert.show({
                title: '',
                content: '网络异常，请稍后重试'
              })
            })


          }
        })
    },

    getQal() {
      if(this.$route.params.qualt){
        this.qualty = this.$route.params.qualt
        this.qualty.cTransactionNbr = this.$route.params.ctn
        this.qualty.cModStauts = this.$route.params.cModStauts
        if(!this.$route.params.ctn){
          this.showOr = false
        }
      }
    }
  }
}
</script>
<style type="text/scss" lang="scss" scoped>
@import "./personstyle";
</style>

